package main

import "fmt"

type Persion struct {
	name string
	sex byte
	age int
}

type Student struct {
	Persion
	id int
	addr string
}

type Teacher struct {
	Persion
	id int
	name string
}

func main()  {
	//初始化
	a := Student{Persion{"make", 'm', 20}, 1, "C++"}
	//%+v 详细打印
	fmt.Printf("a = %+v\n", a)

	//只操作个别成员,其他没有操作的成员为0或者空
	b := Student{id:1}
	fmt.Printf("b = %+v\n", b)
	//给结构体里边的结构体的成员赋值:结构体名字:结构体名字{成员:值}
	c := Student{Persion:Persion{name:"go"}, addr:"SSS"}
	fmt.Printf("c = %+v\n", c)

	//单个赋值
	var d = Student{}
	d.addr = "AAA"
	d.name = "BBB"
	d.id = 666
	d.age = 23
	d.sex = 'f'
	fmt.Printf("d = %+v\n", d)

	//同名字段赋值方式
	//自动推导类型
	e := Teacher{Persion:Persion{name:"YYYY"}, name:"UUU"}
	fmt.Printf("e = %+v\n", e)
	//单个成员赋值
	var f  =Teacher{}
	f.Persion.name = "NNN"
	f.name = "MMM"
	fmt.Printf("f = %+v\n", f)
}
